package core;


import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.util.ArrayList;

import cPanes.CPane;


import uiComponents.MainWindow;
/**
 * Keeps track of windows, maintains clipboard.
 */
public class WindowManager implements WindowListener{
	private ArrayList<MainWindow> windows = new ArrayList();
	private CPane clipboard;
	
	public WindowManager(){
		MainWindow w = new MainWindow(this, "Window " + windows.size());
		w.addWindowListener(this);
		windows.add(w);
	}
	/**
	 * Creates a new blank window, adds it to windows
	 */
	public void newBlankWindow(){
		MainWindow w = new MainWindow(this, "Window " + windows.size());
		w.addWindowListener(this);
		windows.add(w);
	}
	/**
	 * Creates a new window containing the objects from c, adds it to windows
	 * 
	 * @param c The array of CPanes to add
	 */
	public void newWindow(CPane[] c){
		MainWindow w = new MainWindow(this, "Window " + windows.size());
		w.addWindowListener(this);
		for (int i=0; i<c.length; i++){
			w.getScrollPane().add(c[i]);
		}
		windows.add(w);
	}
	/**
	 * Creates a new window with contents and a name
	 * @param c The CPanes to add to the window
	 * @param name The title of the window
	 */
	public void newWindow(CPane[] c, String name){
		MainWindow w = new MainWindow(this, name);
		w.addWindowListener(this);
		for (int i=0; i<c.length; i++){
			w.add(c[i]);
		}
		windows.add(w);
	}
	/**
	 * Moves the CPane to the clipboard. This should be a clone(), to avoid removing the CPane when it's pasted.
	 * @param c The CPane to move
	 */
	public void toClipboard(CPane c){
		clipboard = c;
	}
	/**
	 * Returns the contents of the clipboard.
	 * @return The CPane currently on the clipboard
	 */
	public CPane getClipboard(){
		return clipboard;
	}
	
	public void windowActivated(WindowEvent arg0) {
		//No action
	}

	public void windowClosed(WindowEvent arg0) {
		windows.remove(arg0.getSource());
	}

	public void windowClosing(WindowEvent arg0) {
		//No action
		
	}
	
	public void windowDeactivated(WindowEvent arg0) {
		//No action
		
	}

	public void windowDeiconified(WindowEvent arg0) {
		//No action
		
	}

	public void windowIconified(WindowEvent arg0) {
		//No action
		
	}
	
	public void windowOpened(WindowEvent arg0) {
		//No action
		
	}
	
}
